import time
from distutils.command.check import check
from pickletools import long1
from time import sleep, process_time_ns

from Tools.scripts.cleanfuture import dryrun
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

from common.com import forum, Driver
#注册页面的测试
class epega:
    driver = ""
    def __init__(self):
        self.driver = forum.driver

    #元素检查
    def eCheck(self):
        #返回首页
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a").click()
        #点击发布帖子按钮
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #查找板块选择元素
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad")
        #查找标题输入框
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        #查找内容编辑框
        self.driver.find_element(By.CSS_SELECTOR, "#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre")
        time.sleep(1)
        #寻找发布按钮
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit")
        time.sleep(2)

    #功能测试
    def eFuncTest(self):
        #测一：正常发布一篇帖子因为编辑框是外置的所以导致无法交互
        #默认发布Java板块
        # #找到标题输入框和内容编辑框进行编辑然后点击发布
        # self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("测试帖子1")
        # self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div").send_keys("自动化测试中")
        # time.sleep(2)
        # self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        # time.sleep(5)

        #测试二：不输入帖子的标题进行发布
        # 使用Actions链模拟点击
        time.sleep(1)
        element = self.driver.find_element(By.ID, "article_post_submit")
        ActionChains(self.driver).move_to_element(element).click().perform()

        #检查提示
        text1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div").text
        print(text1)
        #进行截图验证
        forum.getscreenshot()

        ############################
        #测三：输入标题但输入内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("测试帖子1")
        # 使用Actions链模拟点击
        time.sleep(1)
        element1 = self.driver.find_element(By.ID, "article_post_submit")
        ActionChains(self.driver).move_to_element(element1).click().perform()

        #查找提示
        text2 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right").text
        #打印验证
        print(text2)
        #进行截图验证
        forum.getscreenshot()
        #刷新页面进行返回
        # 返回首页
        time.sleep(1)
        element2 = self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a")
        ActionChains(self.driver).move_to_element(element2).click().perform()

        time.sleep(2)

# epega = epega()
# epega.eCheck()
# epega.eFuncTest()